package easy.相同的树;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }

    public static void main(String[] args) {
        TreeNode p = new TreeNode(1, null, new TreeNode(2, new TreeNode(3), null));
        TreeNode q = new TreeNode(1, null, new TreeNode(2, new TreeNode(4), null));
        Solution solution = new Solution();
        System.out.println(solution.isSameTree(p, q));
    }
}
